package com.aso114.project.adapter;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.aso114.project.R;
import com.aso114.project.base.BaseApplication;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ZhiNanAdapter extends BaseAdapter {

    private int[] imageRes;
    private String[] name;
    int is_vip = 0;
    public ZhiNanAdapter(int[] imageRes, String[] name,int viptype) {
        this.imageRes = imageRes;
        this.name = name;
        is_vip = viptype;
    }

    @Override
    public int getCount() {
        return imageRes.length;
    }

    @Override
    public Object getItem(int i) {
        return imageRes[i];
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        GridAdapter.ViewHolder holder = null;
        if (convertView != null) {
            holder = (GridAdapter.ViewHolder) convertView.getTag();
        } else {
            convertView = LayoutInflater.from(BaseApplication.getInstance().getBaseContext()).inflate(R.layout.zhinan_item, parent, false);
            holder = new GridAdapter.ViewHolder(convertView);
            convertView.setTag(holder);
        }

        ImageView ivvip = (ImageView)convertView.findViewById(R.id.iv_vvip);
        //名称
        holder.tvName.setText(TextUtils.isEmpty(name[position]) ? "" : name[position]);
        //图片
        holder.ivIcon.setImageResource(imageRes[position]);
        if(position==3){
            //判断是否是会员  是会员显示 不是 隐藏

            if(is_vip==0){

                ivvip.setVisibility(View.GONE);
            }else{
                ivvip.setVisibility(View.VISIBLE);
            }

        }
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.iv_icon)
        ImageView ivIcon;

        @BindView(R.id.tv_name)
        TextView tvName;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}

